﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.system.basis
{
    public partial class parts : System.Web.UI.Page
    {
        Maticsoft.BLL.InventoryClass blls = new Maticsoft.BLL.InventoryClass();
        Maticsoft.BLL.Parts bll = new Maticsoft.BLL.Parts();
        Maticsoft.BLL.style stylebll = new Maticsoft.BLL.style();
        Maticsoft222.BLL.sqlexec sbll = new Maticsoft222.BLL.sqlexec();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["id"] != "0" && !string.IsNullOrEmpty(Request["id"]))
                {
                    string where = "id<>0 and clnvCCode = '" + Request["id"] + "'";
                    hidwhere.Value = where;
                }
                this.typelist.DataSource = sbll.exsql("select cInvCCode as parentcode,case when iinvcgrade =1 then '┊┈'+cInvCName  when iinvcgrade =2 then '┊┈┊┈'+cInvCName when iinvcgrade =3 then '┊┈┊┈┊┈'+cInvCName when iinvcgrade =4 then '┊┈┊┈┊┈┊┈'+cInvCName end as parentname from dbo.InventoryClass where (cInvCCode like '05%') order by cinvccode");
                this.typelist.DataTextField = "name";
                this.typelist.DataValueField = "code";
                this.typelist.DataBind();
                this.typelist.Items.Insert(0, new ListItem("--请选择商品分类--", ""));

                Maticsoft222.DBUtility.TreeHelper th = new Maticsoft222.DBUtility.TreeHelper();
                List<TreeNode> allNodes = th.GetAllNodes(blls.GetList("(cInvCCode like '05%')").Tables[0], "cInvCCode", "cInvCName");
                th.AutoTreeView(tv, allNodes);//加载树
                int totalOrders = bll.GetRecordCount(hidwhere.Value);
                AspNetPager1.RecordCount = totalOrders;
            }
        }
        void bindData(string where)
        {
            DataSet ds = bll.GetListByPage(where, "clnvCCode", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                //初始化第一条尺寸
                hidcode.Value = ds.Tables[0].Rows[0]["code"].ToString();
            }
            Repeater1.DataSource = ds;
            Repeater1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            bindData(hidwhere.Value);
        }
        protected string gettypename(string code)
        {
            if (string.IsNullOrEmpty(code))
                return "";
            else
                return blls.GetModelList("cInvCCode='" + code + "'")[0].cInvCName;
        }

        protected void btnserach_Click(object sender, EventArgs e)
        {
            string where = "id<>0 ";
            if (typelist.SelectedItem.Value != "")
            {
                where += " and clnvCCode = '" + typelist.SelectedItem.Value + "'";
            }
            if (name.Value != null && !string.IsNullOrEmpty(name.Value))
            {
                where += " and name like '%" + name.Value + "%'";
            }
            hidwhere.Value = where;
            bindData(hidwhere.Value);
        }
        //protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        //{
        //    HiddenField hidcode = e.Item.FindControl("hidcode") as HiddenField;
        //    hidbeifenhidcode.Value = hidcode.Value;

        //    //rptstyle.DataSource = stylebll.GetListByPage("partscode='" + hidcode.Value + "'", "code", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
        //    //rptstyle.DataBind();
        //}
    }
}